﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Data.SqlClient;

using EHTSaleManager.Code;
using EHTSaleManager.Code.BLL;
using EHTSaleManager.Code.Utility;
using EHTSaleManager.Code.Entity;

namespace EHTSaleManager
{
    public partial class IndexProductDetails : System.Web.UI.Page
    {        
        private int ProductID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ProductID = Int32.Parse(Request.QueryString["ProductID"].ToString());
            }
            catch (Exception ex)
            {
                ProductID = 0;
            }
            
            if (!Page.IsPostBack)
            {
                LoadData(ProductID);
                ltrVote.Text = HelpMethod.CreateAllButtonShared("http://re-konsult.com/IndexProductDetails.aspx?ProductID="+ProductID, ProductProvider.GetProductsByProductID(ProductID).ProductName.ToString());
            }

        }
       
        public void LoadData(int proID)
        {
            Product theProduct = ProductProvider.GetProductsByProductID(proID);
            lblPricePerUnit.Text = theProduct.PricePerUnit.ToString();
            lbName.Text = theProduct.ProductName;
            lbPrice.Text = theProduct.Price.ToString();
            lbQuantityPerUnit.Text = theProduct.QuantityPerUnit.ToString();
            ImgProduct.ImageUrl = theProduct.PictureUrl.ToString();
            lbDiscount.Text = theProduct.Discount.ToString();
            this.lbUnitInStock.Text = theProduct.UnitsInStock.ToString();
            this.lbDescription.Text = theProduct.Description.ToString();
           
        }

        protected void ImgBuy_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                int quantity = Int32.Parse(txtquantity.Text.ToString());
                txtquantity.Text = quantity.ToString();
                if (quantity == 0)
                {
                    ltrMessage.Text = "Vennligst skriv inn mengde";
                    Response.Redirect("IndexProductDetails.aspx");
                }
                else {
                    ShoppingCart.Instance.AddItem(ProductID, quantity);
                    Response.Redirect("IndexViewCart.aspx");
                }
                
            }
            catch (Exception ex)
            {
                ltrMessage.Text = "Erorr: Antall er ikke numberic";
            }
            
            
        }
               
    }
}